package com.fieldchain.ex.fa100.utils.version;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.fieldchain.ex.fa100.access.MyApplication;


/**
 * Created by 123 on 2018/5/21.
 */

public class VersionUtils {
    /**
     * 获取本地软件版本号
     */
    public static int getLocalVersion() {
        int localVersion = 0;
        try {
            PackageInfo packageInfo = MyApplication.getAppContext()
                    .getPackageManager()
                    .getPackageInfo(MyApplication.getAppContext().getPackageName(), 0);
            localVersion = packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }

    /**
     * 获取本地软件版本号名称
     */
    public static String getLocalVersionName() {
        String localVersion = "";
        try {
            PackageInfo packageInfo = MyApplication.getAppContext().getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(MyApplication.getAppContext().getPackageName(), 0);
            localVersion = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }
}
